package main

import (
	_ "choujiang/routers"
	_ "github.com/go-sql-driver/mysql"
	_ "choujiang/models"
	"github.com/astaxie/beego"
	_ "choujiang/controllers"
	"os"
	"github.com/astaxie/beego/orm"
	"github.com/astaxie/beego/plugins/cors"
)

func init() {
	env := os.Getenv("ENV_TIZHIZAIXIAN")
	if env == "ONLINE" {
		beego.LoadAppConfig("ini", "conf/app.conf")
		orm.RegisterDataBase("default", "mysql", "root:myDehexin2018mysql@tcp(127.0.0.1:3306)/choujiang?charset=utf8&loc=Local")
	} else if env == "ONLINETEST" {
		orm.RegisterDataBase("default", "mysql", "root:myDehexin2018mysql@tcp(127.0.0.1:3306)/choujiang?charset=utf8&loc=Local")
	} else {
		orm.RegisterDataBase("default", "mysql", "root:vrjiaju2016mysql@tcp(127.0.0.1:3306)/choujiang?charset=utf8&loc=Local")
	}
	orm.RunSyncdb("default", false, true)
}

func main() {
	setSatics()
	beego.BConfig.WebConfig.Session.SessionOn = true
	beego.InsertFilter("*", beego.BeforeRouter, cors.Allow(&cors.Options{
		AllowOrigins:     []string{"*"},
		AllowMethods:     []string{"PUT", "PATCH", "POST", "OPTIONS"},
		AllowHeaders:     []string{"Origin"},
		ExposeHeaders:    []string{"Content-Length"},
		AllowCredentials: true,
	}))
	beego.Run()
}

func setSatics() {
	beego.SetStaticPath("/MP_verify_cLJcy53klwM6ES2m.txt","/home/www/MP_verify_cLJcy53klwM6ES2m.txt")
	beego.SetStaticPath("/js", "views/js")
	beego.SetStaticPath("/img", "views/img")
	beego.SetStaticPath("/css", "views/css")
}

